package com.spring.example.controller;

import com.spring.example.rocket.MessageSendResult;
import com.spring.example.rocket.MqMessage;
import com.spring.example.rocket.MqProducerTemplate;
import com.spring.example.rocket.dto.TestDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rocket")
public class TestRocketMq {

    @Autowired
    private MqProducerTemplate mqProducerTemplate;

    @GetMapping("/send")
    public String send(@RequestParam String msg) {
        TestDto testDto = new TestDto();
        testDto.setName("xiaochi_"+msg);
        testDto.setAge(18);
        MqMessage<TestDto> testMessage = new MqMessage<>();
        testMessage.setBody(testDto);
        testMessage.setTopic("test-topic");
        testMessage.setTag("test-topic-001");
        MessageSendResult rs = mqProducerTemplate.send(testMessage);
        return "success";
    }
}
